const express = require("express");
const router = express.Router();
const Hospitel = require("../../models/Hospitel");

let user_id = "5e7cd7bd378fc14005b4299d";

router.post("/hospitels", async (req, res) => {
  req.body.user_id = user_id;
  const model = await Hospitel.create(req.body);
  res.send(model);
});

router.get("/hospitels", async (req, res) => {
  const model = await Hospitel.find();
  res.send(model);
});

router.put("/hospitels/:id", async (req, res) => {
  const model = await Hospitel.findById(req.params.id);
  model.user_id = user_id;
  await model.save();
  res.send(model);
});

router.delete("/hospitels/:id", async (req, res) => {
  const model = await Hospitel.findByIdAndRemove(req.params.id);
  res.send(model);
});

module.exports = router;
